@file:Suppress("UNCHECKED_CAST")

package com.tokenplus.thai.extend

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import com.tokenplus.thai.assetdetail.AssetDetailActivity
import com.tokenplus.thai.assetdetail.AssetDetailResultActivity
import com.tokenplus.thai.changepassword.PasswordNewInputActivity
import com.tokenplus.thai.changepassword.PasswordVerifyInputActivity
import com.tokenplus.thai.checkin.CheckinActivity
import com.tokenplus.thai.coupons.CouponsActivity
import com.tokenplus.thai.create.CreateWalletNewActivity
import com.tokenplus.thai.create.CreateWalletVerifyActivity
import com.tokenplus.thai.create.InputWalletVerifyActivity
import com.tokenplus.thai.earn.invite.InviteDetailActivity
import com.tokenplus.thai.earn.rules.InviteEarnRulesActivity
import com.tokenplus.thai.earn.rules.TransferEarnRulesActivity
import com.tokenplus.thai.earn.todayEarn.TotalEarnActivity
import com.tokenplus.thai.earn.todayEarn.TotalEarnDetailActivity
import com.tokenplus.thai.earn.todayEarn.TotalEarnDetailWithdrawalTimesActivity
import com.tokenplus.thai.earn.withdraw.WithdrawActivity
import com.tokenplus.thai.earn.withdraw.WithdrawForInviteEarnActivity
import com.tokenplus.thai.earn.withdraw.WithdrawTransferResultActivity
import com.tokenplus.thai.enums.PageTagEnum
import com.tokenplus.thai.home.HomeActivity
import com.tokenplus.thai.invite.InviteActivity
import com.tokenplus.thai.launch.LoginInputMobileActivity
import com.tokenplus.thai.me.*
import com.tokenplus.thai.mywallet.AddWalletActivity
import com.tokenplus.thai.mywallet.ManageWalletActivity
import com.tokenplus.thai.mywallet.MyWalletActivity
import com.tokenplus.thai.newcomerenjoy.NewComerEnjoyActivity
import com.tokenplus.thai.receive.ReceiveActivity
import com.tokenplus.thai.transfer.TransferActivity
import com.tokenplus.thai.transfer.TransferResultActivity
import com.tokenplus.thai.webview.AppWebViewActivity

inline fun <reified T> AppCompatActivity.startToNextActivity(params: HashMap<String, String> = HashMap()) {
    try {
        val intent = Intent(this, T::class.java)
        params.keys.forEach { gkey ->
            intent.putExtra(gkey, params[gkey])
        }
        startActivity(intent)
    } catch (e: Exception) {
        e.printStackTrace()
    }
}

inline fun <reified T> AppCompatActivity.startToNextActivityAndFinish(
    params: HashMap<String, String> = HashMap()
) {
    try {
        val intent = Intent(this, T::class.java)
        params.keys.forEach { gkey ->
            intent.putExtra(gkey, params[gkey])
        }
        startActivity(intent)
        finish()
    } catch (e: Exception) {
        e.printStackTrace()
    }
}

inline fun <reified T> AppCompatActivity.startToNextActivityForSingleTop(
    params: HashMap<String, String> = HashMap()
) {
    try {
        val intent = Intent(this, T::class.java)
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
        params.keys.forEach { gkey ->
            intent.putExtra(gkey, params[gkey])
        }
        startActivity(intent)
        finish()
    } catch (e: Exception) {
        e.printStackTrace()
    }
}

fun AppCompatActivity.startToNextFromPage(
    pageTag: PageTagEnum,
    params: HashMap<String, String> = HashMap()
) {
    try {

    } catch (e: Exception) {
        e.printStackTrace()
    }
}

//////////////////////////////////////////////////////////////////////////////
/** 启动登录页-输入手机号页 */
fun AppCompatActivity.startToLoginActivity() {
    startToNextActivityForSingleTop<LoginInputMobileActivity>()
}

/** 启动创建钱包页-输入密码页 */
fun AppCompatActivity.startToInputWalletNewActivity(hashMap: HashMap<String, String>) {
    startToNextActivity<InputWalletVerifyActivity>(hashMap)
}

/** 启动创建钱包页-生成密码页 */
fun AppCompatActivity.startToCreateWalletNewActivity(hashMap: HashMap<String, String>) {
    startToNextActivity<CreateWalletNewActivity>(hashMap)
}

/** 启动创建钱包页-密码难忘页 */
fun AppCompatActivity.startToCreateWalletVerifyActivity(hashMap: HashMap<String, String>) {
    startToNextActivity<CreateWalletVerifyActivity>(hashMap)
}

/** 启动首页 */
fun AppCompatActivity.startToHomeActivity() {
    startToNextActivityForSingleTop<HomeActivity>()
}

/** 启动我的钱包页 */
fun AppCompatActivity.startToMyWalletActivity() {
    startToNextActivity<MyWalletActivity>()
}

/** 启动我的-新增钱包页 */
fun AppCompatActivity.startToAddWalletActivity() {
    startToNextActivity<AddWalletActivity>()
}

/** 启动管理钱包页 */
fun AppCompatActivity.startToManageWalletActivity(hashMap: HashMap<String, String>) {
    startToNextActivity<ManageWalletActivity>(hashMap)
}

/** transfer页 */
fun AppCompatActivity.startToTransferActivity(hashMap: HashMap<String, String>) {
    startToNextActivity<TransferActivity>(hashMap)
}

/** transfer result页 */
fun AppCompatActivity.startToTransferResultActivity(hashMap: HashMap<String, String>) {
    startToNextActivity<TransferResultActivity>(hashMap)
}

/** receive页 */
fun AppCompatActivity.startToReceiveActivity() {
    startToNextActivity<ReceiveActivity>()
}

/** asset detail 页 */
fun AppCompatActivity.startToAssetDetailActivity(hashMap: HashMap<String, String>) {
    startToNextActivity<AssetDetailActivity>(hashMap)
}

/** asset detail result 页 */
fun AppCompatActivity.startToAssetDetailResultActivity() {
    startToNextActivity<AssetDetailResultActivity>()
}

/** earn-withdraw 页 */
fun AppCompatActivity.startToWithdrawActivity() {
    startToNextActivity<WithdrawActivity>()
}

/** earn-withdraw-invite 页 */
fun AppCompatActivity.startToWithdrawForInviteEarnActivity() {
    startToNextActivity<WithdrawForInviteEarnActivity>()
}

/** invite detail 页 */
fun AppCompatActivity.startToInviteDetailActivity() {
    startToNextActivity<InviteDetailActivity>()
}

/** today earn 页 */
fun AppCompatActivity.startToTotalEarnActivity() {
    startToNextActivity<TotalEarnActivity>()
}

/** today earn detail 页 */
fun AppCompatActivity.startToTotalEarnDetailActivity() {
    startToNextActivity<TotalEarnDetailActivity>()
}

/** today earn detail withdrawal detail 页 */
fun AppCompatActivity.startToTotalEarnDetailWithdrawalTimesActivity() {
    startToNextActivity<TotalEarnDetailWithdrawalTimesActivity>()
}

/** earn withdraw result 页 */
fun AppCompatActivity.startToEarnWithdrawTransferResultActivity(hashMap: HashMap<String, String>) {
    startToNextActivity<WithdrawTransferResultActivity>(params = hashMap)
}

/** earn rules transfer 页 */
fun AppCompatActivity.startToTransferEarnRulesActivity() {
    startToNextActivity<TransferEarnRulesActivity>()
}

/** earn rules invite 页 */
fun AppCompatActivity.startToInviteEarnRulesActivity() {
    startToNextActivity<InviteEarnRulesActivity>()
}

/** invite 页 */
fun AppCompatActivity.startToInviteActivity() {
    startToNextActivity<InviteActivity>()
}

/** setting 页 */
fun AppCompatActivity.startToSettingActivity() {
    startToNextActivity<SettingActivity>()
}

/** term of use 页 */
fun AppCompatActivity.startToTermOfUseActivity() {
    startToNextActivity<TermsOfUseWebViewActivity>()
}

/** customer service 页 */
fun AppCompatActivity.startToCustomerServiceActivity() {
    startToNextActivity<CustomerServiceActivity>()
}

/** about us 页 */
fun AppCompatActivity.startToAboutUsActivity() {
    startToNextActivity<AboutUsActivity>()
}

/** about us 页 */
fun AppCompatActivity.startToAboutUsWebViewActivity() {
    startToNextActivity<AboutUsWebViewActivity>()
}

/** 启动webview页 */
fun AppCompatActivity.startToAppWebViewActivity() {
    startToNextActivityForSingleTop<AppWebViewActivity>()
}

/** 修改密码-输入助记词 页 */
fun AppCompatActivity.startToPasswordVerifyActivity() {
    startToNextActivity<PasswordVerifyInputActivity>()
}

/** 修改密码-输入新密码 页 */
fun AppCompatActivity.startToPasswordNewInputActivity(hashMap: HashMap<String, String>) {
    startToNextActivity<PasswordNewInputActivity>(params = hashMap)
}

/** checkin 页 */
fun AppCompatActivity.startToCheckinActivity() {
    startToNextActivity<CheckinActivity>()
}

/** coupons 页 */
fun AppCompatActivity.startToCouponsActivity() {
    startToNextActivity<CouponsActivity>()
}

/** cash back 页 */
fun AppCompatActivity.startToNewComerEnjoyActivity() {
    startToNextActivity<NewComerEnjoyActivity>()
}